<template>
  <el-card id="moreProfile">

    <div id="updatePwd">
      <div>
        <h3>优能好友申请</h3>
         <el-form ref="form" label-width="80px">
            <el-form-item label="姓名">
              <el-input v-model="profile.name" placeholder="姓名" ></el-input>
            </el-form-item>
            <el-form-item label="性别">
              <el-radio-group  v-model="profile.sex" >
                <el-radio v-model="profile.sex" label="男"> <span>男</span>  </el-radio>
                <el-radio v-model="profile.sex" label="女"> <span>女</span>  </el-radio>
              </el-radio-group>
            </el-form-item>
            <el-form-item label="出生年月">
              
              <el-date-picker type="date" placeholder="选择日期" v-model="profile.birthday" style="width: 100%;"></el-date-picker>
            </el-form-item>
            <el-form-item label="微信号">
              <el-input v-model="profile.wechat" placeholder="微信号  提示:非微信名" ></el-input>
            </el-form-item>
            <el-form-item label="邮箱">
              <el-input v-model="profile.mailbox" placeholder="邮箱" ></el-input>
            </el-form-item>
            <el-form-item label="公司">
              <el-input v-model="profile.company" placeholder="公司" ></el-input>
            </el-form-item>
            <el-form-item label="职位">
              <el-input v-model="profile.position" placeholder="职位"></el-input>
            </el-form-item>
            <el-form-item label="推荐人">
              <el-input v-model="profile.recommender" placeholder="推荐人"></el-input>
            </el-form-item>
            <el-form-item label="成为讲师">
              <el-radio-group  v-model="profile.isLecture" >
                <el-radio v-model="profile.isLecture" label="是"> <span>是</span>  </el-radio>
                <el-radio v-model="profile.isLecture" label="否"> <span>否</span>  </el-radio>
              </el-radio-group>
            </el-form-item>
            <el-form-item label="成为志愿者">
              <el-radio-group  v-model="profile.isVolunteer" >
                <el-radio v-model="profile.isVolunteer" label="是"> <span>是</span>  </el-radio>
                <el-radio v-model="profile.isVolunteer" label="否"> <span>否</span>  </el-radio>
              </el-radio-group>
            </el-form-item>
            <el-button icon="el-icon-cherry" @click="updateInfo()">提交</el-button>
        </el-form>
      </div>

    </div>

    <el-divider/>

  </el-card>
</template>

<script>
  import user from '@/api/user'

  export default {
    name: 'account',
    data() {
      return {
        profile:{
          name:'',
          sex :'',
          birthday : '',
          wechat   : '',
          mailbox  : '',
          company  : '',
          position : '',
          recommender : '',
          isLecture: '',
          isVolunteer:''

        }
      }
    },
    created() {
      this.load();
    },
    methods: {
        load() {
          // user.getUserMail().then(res => {
          //  this.mail = res.data;
          //})
          
        },
        getToken() {
          return {'Authorization': this.$store.state.token}
        },        
        updateInfo(){
          console.log(this.profile)
          if (this.profile.name.length <= 0) {
            this.$message({
              message: '名字不能为空',
              type: 'error'
            });
            return;
          }
          if (this.profile.birthday.length <= 0) {
            this.$message({
              message: '生日不能为空',
              type: 'error'
            });
            return;
          }
          if("2019-10-10 00:00:00".length != this.profile.birthday.length){
            var ttt = this.profile.birthday.toLocaleDateString().replace(/\//g, "-") + " " + this.profile.birthday.toTimeString().substr(0, 8); 
            console.log(ttt)
            this.profile.birthday = ttt;
          }
          console.log(this.profile.birthday)
          if (this.profile.mailbox.length <= 0) {
            this.$message({
              message: '邮箱不能为空',
              type: 'error'
            });
            return;
          }

          user.updatePeerInfo(this.profile).then(res => {
            this.$message({
              message: '尤能好友信息提交成功',
              type: 'success'
            });
            this.$router.push({ //路由跳转
               path: '/'
            })
            // this.newMail = '';
            // this.oldMailCode = '';
            // this.newMailCode = '';
            // this.load();
          })
        },

    },
  }
</script>
<style scoped>
  #account {
    margin: 1% 5%;
    text-align: left;
  }



  #updateReward {
    padding-left: 30%;
    width: 30%;
  }
  .el-form-item__label {
    text-align: left;
    vertical-align: middle;
    float: left;
    font-size: 14px;
    color: #606266;
    line-height: 40px;
    padding: 0 5px 0 0;
  }
  .avatar-uploader .el-upload {
    border: 1px dashed #000000;
    border-radius: 6px;
    cursor: pointer;
    position: relative;
    overflow: hidden;
  }

  .avatar-uploader .el-upload:hover {
    border-color: #000000;
  }

  .avatar-uploader-icon {
    font-size: 28px;
    color: #8c939d;
    width: 176px;
    height: 176px;
    text-align: center;
  }

  .avatar {
    width: 176px;
    height: 176px;
    display: block;
  }

</style>
